package com.zj.controller;

import com.zj.common.FileUtil;
import com.zj.common.Msg;
import com.zj.common.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/upload")
public class UploadController {
    @PostMapping
    public Result upload(MultipartFile file) throws IOException {
        if (file.isEmpty()){
            return Result.error(Msg.UPLOAD_IS_ERROR);
        }else {
            FileUtil fileUtil = new FileUtil();
            String url =fileUtil.upload(file);
            return Result.success(url,Msg.UPLOAD_IS_SUCCESS);
        }
    }

}
